
//window.__API = "https://site.xn--rss28cz9ei8z.cn/dev/web"
window.__API = "https://xn--rss28cz9ei8z.cn/oapi"

$(function(){
    // 高亮导航 // TODO 考虑更灵活的带参的url
    var pathname = window.location.pathname
    var search = window.location.search
    var link = pathname + search
    if (link=='/') link = "/index.html"
    $(".nav-link[href='"+ link +"']").addClass("active")
})

// 获取url参数
function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){
            return pair[1];
        }
    }
    return(false);
}

/* 
* 替换或增加URL的参数值
* url 目标url
* arg 需要替换的参数名称，如果原来没有，会自动加上
* arg_val 替换后的参数的值 
* return url 参数替换后的url 
*/
function changeURLArg(url, arg, arg_val) {
    var pattern = arg + '=([^&]*)';
    var replaceText = arg + '=' + arg_val;
    if (url.match(pattern)) {
        var retuenUrl = url;
        var temp = '/(\&' + arg + '=)([^&]*)/gi';
        if (eval(temp).test(retuenUrl)) {
        retuenUrl = retuenUrl.replace(eval(temp), '&' + replaceText);
        }
        var temps = '/([\?])(' + arg + '=)([^&]*)/gi';
        if (eval(temps).test(retuenUrl)) {
        retuenUrl = retuenUrl.replace(eval(temps), '?' + replaceText);
        }
        return retuenUrl;
    }
    else {
        // if (url.match('[\?]')) {
        if (url.indexOf('?') > 0) {
            return url + "&" + replaceText;
        } else {
            return url + "?" + replaceText;
        }
    }
    return url + '\n' + arg + '\n' + arg_val;
}

